package com.cx.base.day15_socket.udp.user2;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class Receive implements Runnable {
    DatagramSocket ds = null;
    DatagramPacket dp = null;
    byte[] bytes = new byte[1024];

    @Override
    public void run() {
        try {
            ds = new DatagramSocket(10002);
            dp = new DatagramPacket(bytes, bytes.length);
            ds.receive(dp);
            String ip = dp.getAddress().getHostAddress();
            int port = dp.getPort();
            String text = new String(dp.getData(), 0, dp.getLength());
            System.out.println(ip + "::" + text);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
